package com.studyyoun.android.nonghe.home.adapter;
/**
 * Created by zhaolong on 2017/10/14.
 * 站在顶峰，看世界
 * 落在谷底，思人生
 */

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.studyyoun.android.nonghe.R;
import com.studyyoun.android.nonghe.home.activity.AppVersonActivity;
import com.studyyoun.android.nonghe.home.activity.ArtDetaileActivity;
import com.studyyoun.android.nonghe.home.activity.VideoDetaileActivity;
import com.studyyoun.android.nonghe.push.JPushReceiverModel;
import com.studyyoun.android.nonghe.welcom.App;

import java.util.List;

/**
 * class infation
 */
public class JpushMsgAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    List<JPushReceiverModel> mJPushReceiverModels;

    public JpushMsgAdapter(Context context, List<JPushReceiverModel> jPushReceiverModels) {
        mContext = context;
        mJPushReceiverModels = jPushReceiverModels;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(mContext, R.layout.item_jpush_msg, null);
        return new JpushMsgViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        JpushMsgViewHolder viewHolder = (JpushMsgViewHolder) holder;
        JPushReceiverModel jPushReceiverModel = mJPushReceiverModels.get(position);
        viewHolder.setdatas(jPushReceiverModel);

    }

    @Override
    public int getItemCount() {
        return mJPushReceiverModels.size();
    }

    public void setListDatas(List<JPushReceiverModel> jPushReceiverModels) {
        mJPushReceiverModels = jPushReceiverModels;
    }


    private static class JpushMsgViewHolder extends RecyclerView.ViewHolder {

        private final TextView mTitleTextView;

        public JpushMsgViewHolder(View itemView) {
            super(itemView);
            mTitleTextView = itemView.findViewById(R.id.tv_item_jpush_title);
        }

        public void setdatas(final JPushReceiverModel jPushReceiverModel) {

            mTitleTextView.setText(jPushReceiverModel.msgTitle + "：" + jPushReceiverModel.msgContent);

            mTitleTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String type = jPushReceiverModel.type;
                    if (TextUtils.equals(type, "art")) {
                        //查看文章详情
                        Intent intent = new Intent(App.getInstance(), ArtDetaileActivity.class);
                        intent.putExtra("artModelId", jPushReceiverModel.id);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        App.getInstance().startActivity(intent);
                    } else if (TextUtils.equals(type, "video")) {
                        //查看视频详情
                        Intent intent = new Intent(App.getInstance(), VideoDetaileActivity.class);
                        intent.putExtra("videoId", jPushReceiverModel.id);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        App.getInstance().startActivity(intent);
                    } else if (TextUtils.equals(type, "app")) {
                        //查看版本信息
                        //查看视频详情
                        Intent intent = new Intent(App.getInstance(), AppVersonActivity.class);
                        intent.putExtra("videoId", jPushReceiverModel.id);
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        App.getInstance().startActivity(intent);
                    }
                }
            });
        }
    }
}
